<?php

/**
 * 阿里云物联网sdk封装
 * @author zhanghao<zh002919@outlook.com>
 * @date 2022-07-06
 */

namespace app\common\components;

use yii\base\Component;
use \Iot\Request\V20180120 as Iot;

include_once 'aliyun-php-sdk-core/Config.php';

class AliIot extends Component
{
    public function demo()
    {
        //设置您的AccessKeyId/AccessSecret/ProductKey
        $accessKeyId = "";
        $accessSecret = "";
        $iClientProfile = DefaultProfile::getProfile("cn-shanghai", $accessKeyId, $accessSecret);
        $client = new DefaultAcsClient($iClientProfile);
        $request = new Iot\PubRequest();
        $request->setIotInstanceId("iotInstanceId");
        $request->setProductKey("productKey");
        $request->setMessageContent("aGVsbG93b3JsZA="); //hello world Base64 String.
        $request->setTopicFullName("/productKey/deviceName/user/get"); //消息发送到的Topic全名.
        $response = $client->getAcsResponse($request);
        print_r($response);
    }
}
